package simple.example;

class SuperClass1 
{
	private int Number1 = 5, Number2 = 8;
	protected int Total = 0;
	
	SuperClass1(int Numner1, int Numner2)
	{
		this.Number1 = Numner1;
		this.Number2 = Numner2;	
	}
	
	void OnlySuperMethod()
	{
		System.out.println("This method is defined only in Super Class.");
	}
	
	void PrintString()
	{
		System.out.println("This is Super Class.");
	}
	
	void AddTwoNumber()
	{
		Total = Number1 + Number2;
		System.out.println("Total of Super Class is " + Total + ".");
	}
}


class ChildClass1 extends SuperClass1
{
	private int Number3, Number4;
	
	ChildClass1(int Numner1, int Numner2, int Numner3, int Numner4)
	{
		super(Numner1, Numner2);
		/* super keyword is used to pass the values to Parent Class 
		 * using Constructor.
		 */
		this.Number3 = Numner3;
		this.Number4 = Numner4;	
	}
	void PrintString()
	{
		System.out.println("This is Child Class.");
	}
	
	void AddTwoNumber()
	{
		Total = Number3 + Number4;
		System.out.println("Total of Clild Class is " + Total + ".");
	}
}


class Inheritance1
{
	public static void main(String[] args)
	{
		ChildClass1 ChildObj1  = new ChildClass1(5, 8 , 9, 17);
// 		SuperClass1 ParentObj1 = new SuperClass1();
		SuperClass1 ParentObj2 = ChildObj1;
		
	/* Some of the Important point
	 * ChildClass1 ChildObj1  = new ChildClass1();
	 * SuperClass1 ParentObj2 = ChildObj1;
	 * 
	 * Please see the above two statements carefully.
	 * In first statement we have create a Child Class Object and in the 
	 * second statement we have assigned it to Parent Class Object. So In this 
	 * case we can access all child class properties by referring ParentObj2 
	 * (which is also a parent class object). To refer parent class method 
	 * which are already overridden by the child class we have created 
	 * ParentObj1.   
	 */
		ParentObj2.PrintString();
		ParentObj2.AddTwoNumber();
		ParentObj2.OnlySuperMethod();
	}
}